package com.mmall.concurrency.example.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * <p>Descriptions...
 *
 * @author Diamon.Cheng
 * @date 2019/12/9.
 */
@Slf4j
public class FutureTaskExamples {
    
    public static void main(String[] args)  throws  Exception{
    
        FutureTask<String>  futureTask = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                log.info("do something in callable");
                Thread.sleep(5000);
                return "done";
            }
        });
        
        new  Thread(futureTask).start();
        log.info("do something in main");
        Thread.sleep(1000);
        String result = futureTask.get();
        log.info("result：{}", result);
    
    }
}
